package com.yinhai.cp_nzw.utils;

import com.yinhai.cp_nzw.bean.CP;

import java.util.Arrays;
import java.util.Random;

public class GenerateCode {

    public static CP gCode() {
        int[] redBall = new int[6];
        int blueBall = 0;
        Random rand = new Random();
        //1个篮球1~16
        blueBall = rand.nextInt(16) + 1;
        //6个红球 1~33，并且不能重复
        for (int i = 0; i < redBall.length; i++) {
            redBall[i] = rand.nextInt(33) + 1;
            for (int j = 0; j < i; j++) {
                if (redBall[j] == redBall[i]) {//判断重复
                    i--;
                    break;
                }
            }
        }
        Arrays.sort(redBall);//排序
        CP cp = new CP();
        cp.setRed_ball_1(redBall[0] < 10 ? "0" + redBall[0] : redBall[0] + "");
        cp.setRed_ball_2(redBall[1] < 10 ? "0" + redBall[1] : redBall[1] + "");
        cp.setRed_ball_3(redBall[2] < 10 ? "0" + redBall[2] : redBall[2] + "");
        cp.setRed_ball_4(redBall[3] < 10 ? "0" + redBall[3] : redBall[3] + "");
        cp.setRed_ball_5(redBall[4] < 10 ? "0" + redBall[4] : redBall[4] + "");
        cp.setRed_ball_6(redBall[5] < 10 ? "0" + redBall[5] : redBall[5] + "");
        cp.setBlue_ball_1(blueBall < 10 ? "0" + blueBall : blueBall + "");
        cp.setGenerate_date(DateUtils.getNowDate());
        return cp;
    }
}
